package org.zerta.troops.xml;

import java.io.IOException;

import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.zerta.troops.common.World;

public class WorldProcessor {
	
	public World processMapInput( String mapString ) {
		
		WorldUnmarshaler mu = new WorldUnmarshaler();
		
		DOMParser parser = new DOMParser();
		try {
			parser.parse(new InputSource(new java.io.StringReader(mapString)));
		} catch (IOException e) {
			System.err.println("IO-fail when parsing worldString");
			e.printStackTrace(System.err);
			return null;
		} catch (SAXException e ) {
			System.err.println("SAX-fail when parsing worldString");
			return null;
		}
		
		Document doc = parser.getDocument();
		
		World world = mu.unmarshalWorld( doc.getDocumentElement() );
	
		return world;
		
	}
}
